import { getCuesSubmitPage } from '@/services/api/api-cues-submit';
import { findTagColor } from '@/utils/findTagColor';
import { FileImageOutlined, PaperClipOutlined } from '@ant-design/icons';
import { ProCard, ProTable } from '@ant-design/pro-components';
import ProList from '@ant-design/pro-list';
import { ActionType } from '@ant-design/pro-table';
import { Avatar, Space, Spin, Tag } from 'antd';
import moment from 'moment';
import React, { useEffect, useRef, useState } from 'react';
import { useAccess } from 'umi';
// import { useAccess } from 'umi';
// import AddSubmit from '../../submit/components/AddSubmit';
import DetailsSubmit from '../../submit/components/DetailsSubmit';
import AddSubmit from '../../submit/components/AddSubmit';
interface TableTopicSubmitProps {
  mode: number;
  item: CuesTopicData.TopicPage;
  onRefurbish: () => void;
}

const TableTopicSubmit: React.FC<TableTopicSubmitProps> = (props) => {
  const { mode, item, onRefurbish } = props;
  const access = useAccess();
  const ref = useRef<ActionType>();

  return (
    <>
      <ProList<CuesSubmitData.SubmitPage>
        ghost={true}
        // ghost={false}
        // itemCardProps={{
        //   ghost: false,
        // }}
        pagination={{
          defaultPageSize: 8,
          showSizeChanger: false,
          showTotal: false,
          style: { textAlign: 'center' },
        }}
        style={{ marginTop: 10 }}
        actionRef={ref}
        request={async (params = {}) => {
          const response = await getCuesSubmitPage({
            ...params,
            mode,
            topicId: item.id,
          });

          return Promise.resolve({
            data: response.data.data,
            total: response.data.total,
            success: response.code === 0,
          });
        }}
        showActions="hover"
        grid={{ gutter: 18, column: 1 }}
        onItem={(record: any) => {
          return {
            onMouseEnter: () => { },
            onClick: () => { },
          };
        }}
        renderItem={(item: CuesSubmitData.SubmitPage, index: number) => {
          return (
            <DetailsSubmit
              id={item.id}
              name={item.articleName}
              onRefurbish={() => {
                ref.current?.reload()
              }}
              item={item}
              triggerMode="card"
            />
          );
        }}
        rowKey={'id'}
        toolBarRender={(action) => [
          <div style={{ display: 'flex', justifyContent: 'space-between' ,alignItems:'center',width:'85vw'}}>
            <span style={{fontSize:18}}>报送线索</span>
            <div>
              {
                access.线索征集x报送线索x页面 && item.run === 1 && (
                  <AddSubmit
                    key="add_submit"
                    topicId={item.id}
                    topicName={item.name}
                    onRefurbish={() => {
                      action?.reload();
                    }}
                  />
                )
              }
            </div>

          </div>
        ]}
      />
    </>
  );
};

export default TableTopicSubmit;
